<?php

/**
 * Controller_inform
 */

class Controller_inform extends MyApp {

	public function __construct()
	{

		parent::__construct();


		$this->model->department    = YOU::loadModel('department');
		$this->model->inform    	= YOU::loadModel('inform');
		$this->model->appoint    	= YOU::loadModel('appoint');
		$this->model->staff    		= YOU::loadModel('staff');
		$this->model->research    	= YOU::loadModel('research');
		$this->model->prepare    	= YOU::loadModel('prepare');
		$this->model->subject    	= YOU::loadModel('subject');
		$this->model->discipline    = YOU::loadModel('discipline');
		$this->model->grade         = YOU::loadModel('grade');
		$this->model->class         = YOU::loadModel('class');
		$this->model->student       = YOU::loadModel('student');
		$this->model->divide        = YOU::loadModel('divide');
		$this->model->user          = YOU::loadModel('user');
		$this->model->file          = YOU::loadModel('file');
		$this->model->log           = YOU::loadModel('log');

	}
	/** 首页 **/
	public function actionIndex()
	{

		$this->tpl->display();
	}
	/** -------------------------------- 上级通知 -------------------------------- **/
	/** 上级通知列表 **/
	public function actionSuperiorList ()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);


		$inform_type		= 1;
		// 查询条件
		$up_id				= $this->get->up_id;
		$inform_title		= $this->get->inform_title;
		$from				= $this->get->from;
		$to					= $this->get->to;

		$where = "WHERE 1=1  ";
		//搜索条件
		if(!empty($up_id)){

			$where .= " AND up_id ='{$up_id}'";
			$this->tpl->assign("up_id", $up_id);
		}
		if(!empty($inform_title)){

			$where .= " AND inform_title LIKE '%{$inform_title}%'";
			$this->tpl->assign("inform_title", $inform_title);
		}
		if(!empty($from)){

			$where .= " AND end_time >= '{$from}'";
			$this->tpl->assign("from", $from);
		}
		if(!empty($to)){

			$where .= " AND end_time <= '{$to}+1'";
			$this->tpl->assign("to", $to);
		}

		// 上级部门
		$up_lists = $this->model->department->getUpAll();
		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_inform` {$where}");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);
		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}

		$inform_lists = $this->db->fetchAll("SELECT * FROM `tbl_inform` {$where} ORDER BY inform_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
		foreach($inform_lists as $key=>$value){
			// 上级部门
			$department_lists = $this->model->department->getupinfo($value['up_id']);
			$inform_lists[$key]['up_name'] 	=$department_lists['up_name'];

			// 内容解密
			$row = base64_decode($value['inform_content']);
			// 控制内容字数
			if(strlen($row)>=21){

				$inform_lists[$key]['inform_content']=mb_substr($row,0,7,'utf8').'...';
			}

			// 控制标题字数
			if(strlen($inform_lists[$key]['inform_title'])>=60){
				$inform_lists[$key]['inform_title']=mb_substr($value['inform_title'],0,20,'utf8').'...';
			}
		}

		// 所有部门名称
		$department_lists = $this->model->department->getAll();
		// 所有部门任职人员
		$department_name = $this->model->appoint->getSAll();
		foreach ($department_name as $key => $value){
			$row = $this->model->staff->getinfo($value['staff_id']);
			$department_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
			$department_name[$key]['staff_name'] = $row['staff_name'];
		}

		// 所有教研组名称
		$research_lists = $this->model->research->getAll();
		// 所有教研组的任职人员
		$research_name = $this->model->appoint->getRAll();
		foreach ($research_name as $key => $value){
			$row = $this->model->staff->getinfo($value['staff_id']);
			$research_name[$key]['staff_name'] = $row['staff_name'];
			$research_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
		}

		// 所有备课组名称
		$prepare_lists = $this->model->prepare->getAll();
		// 所有备课组的任职人员
		$prepare_name = $this->model->appoint->getPAll();
		foreach ($prepare_name as $key => $value){
			$row = $this->model->staff->getinfo($value['staff_id']);
			$prepare_name[$key]['staff_name'] = $row['staff_name'];
			$prepare_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
		}

		// 学科组
		$discipline_lists = $this->model->discipline->getAll();
		// 所有备课组的任职人员
		$discipline_name = $this->model->appoint->getDAll();
		foreach ($discipline_name as $key => $value){
			$row = $this->model->staff->getinfo($value['staff_id']);
			$discipline_name[$key]['staff_name'] = $row['staff_name'];
			$discipline_name[$key]['user_id'] = $this->model->user->getIdByType("staff", $value['staff_id']);
		}

		// 年级列表
		$grade_lists = $this->model->grade->getIni();
		// 班级列表
		$class_lists = $this->model->class->getAll();
		// 学生按 年级 班级 列出
		$student_lists = $this->db->fetchAll("SELECT a.user_id,b.student_name,b.grade_id,b.class_id FROM `tbl_user` AS a,`tbl_student` AS b WHERE a.type_id=b.student_id AND a.user_type='student' ");

		if ($_POST){
			$pid 		= $this->post->pid;
			$inform_id 	= $this->post->inform_id;

			foreach ($pid as $key => $value){

				if (substr($value,0,4) == 'user') {
					$user_id = substr($value,5,13);

					// 查找阅读表
					$read_data = $this->model->inform->getReadRow($inform_id,$user_id);

					if (empty($read_data)) {

						$info = array(
						"inform_id"   			=> $inform_id,
						"read_to"     			=> $user_id,
						"read_form"   			=> $this->user['user_id'],
						"status"                => 1,
						"is_show"     			=> 0,
						"is_read"     			=> 0,
						"create_time"           => date("Y-m-d H:i:s"),
						"update_time"           => "0000-00-00 00:00:00",
						);
						$this->db->do_insert("tbl_inform_read", $info);
						// 分发成功
						$info = array(
						"inform_distribute"   			=> 1,
						);
						$this->db->do_update("tbl_inform", $info, "inform_id='{$inform_id}'");

					}

				}
			}
			// 跳转
			Helper_Client::location("分发成功", "index.php?a=inform.superiorlist&inform_type={$inform_type}");
		}

		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";
		$this->tpl->assign("page", $page->show(4, "yahoo"));

		$this->tpl->assign("inform_lists", $inform_lists);
		$this->tpl->assign("up_lists", $up_lists);
		$this->tpl->assign("inform_type", $inform_type);

		$this->tpl->assign("department_lists", $department_lists);
		$this->tpl->assign("department_name", $department_name);
		$this->tpl->assign("research_lists", $research_lists);
		$this->tpl->assign("research_name", $research_name);

		$this->tpl->assign("prepare_lists", $prepare_lists);
		$this->tpl->assign("prepare_name", $prepare_name);
		$this->tpl->assign("discipline_lists", $discipline_lists);
		$this->tpl->assign("discipline_name", $discipline_name);

		$this->tpl->assign("grade_lists", $grade_lists);
		$this->tpl->assign("class_lists", $class_lists);
		$this->tpl->assign("student_lists", $student_lists);;
		$this->tpl->display('inform/superior.list.tpl.php');

	}
	/** 上级通知发布 **/
	public function actionSuperiorAdd()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);


		// 类型
		$inform_type	  = (int)$this->get->inform_type;
		// 上级发布部门
		$up_lists = $this->model->department->getUpAll();

		if ($_POST){
			//var_dump($_POST);exit;
			$inform_title		= $this->post->inform_title;
			$inform_num			= $this->post->inform_num;
			$up_id     	    	= $this->post->up_id;
			$start_time     	= $this->post->start_time;
			$end_time     		= $this->post->end_time;
			$inform_content    	= $this->post->inform_content;
			$inform_content = base64_encode($inform_content);
			if(empty($inform_title)){
				Helper_Client::alert("请填写标题");
			}


			// 写入数据库
			$info = array(

			"inform_title"			=> $inform_title,
			"inform_num"			=> $inform_num,
			"up_id"      			=> $up_id,
			"start_time"			=> $start_time,
			"end_time"				=> $end_time,
			"inform_content"		=> $inform_content,
			"inform_type"			=> $inform_type,
			"user_id"           	=>$this->user['user_id'],
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_insert("tbl_inform", $info);
			$inform_id = $this->db->insert_id();

			// 附件上传
			$file = $this->model->file->upload("inform_file", $inform_id, array("txt","ppt", "xls", "xlsx", "docs", "docx","doc", "pdf", "jpg", "png", "gif", "zip", "rar"));
			if (!empty($file)){
				$info = array(
				"inform_file" => $file['fname'],
				);

				$this->db->do_update("tbl_inform", $info, "inform_id='{$inform_id}'");
			}

			// 跳转
			Helper_Client::location("发布成功", "index.php?a=inform.superiorList&inform_type={$inform_type}");
		}

		$this->tpl->assign("up_lists", $up_lists);
		$this->tpl->assign("style_lists", $style_lists);
		$this->tpl->display('inform/superior.add.tpl.php');
	}
	/** 上级通知修改 **/
	public function actionSuperiorUpdate()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);

		// 类型
		$inform_type	  = (int)$this->get->inform_type;
		$inform_id	      = (int)$this->get->inform_id;
		// 获取信息
		$inform_data 	  = $this->model->inform->getinfo($inform_id);
		$inform_data['inform_content'] = base64_decode($inform_data['inform_content']);
		// 上级发布部门
		$up_lists 		  = $this->model->department->getUpAll();
		//$notice_data = $this->db->fetchRow("select * from `tbl_notice` WHERE `user_id` = {$notice_id}");
		$uid = $this->user['user_id'];

		if($inform_data['user_id']  && ($uid !=$inform_data['user_id']) ){
			Helper_Client::alert("对不起无此权限");
			exit;
		}

		if ($_POST){

			$inform_title		= $this->post->inform_title;
			$inform_num			= $this->post->inform_num;
			$up_id     	    	= $this->post->up_id;
			$start_time     	= $this->post->start_time;
			$end_time     		= $this->post->end_time;
			$inform_content    	= $this->post->inform_content;
			$inform_content = base64_encode($inform_content);
			if(empty($inform_title)){
				Helper_Client::alert("请填写标题");
			}

			// 写入数据库
			$info = array(

			"inform_title"			=> $inform_title,
			"inform_num"			=> $inform_num,
			"up_id"      			=> $up_id,
			"start_time"			=> $start_time,
			"end_time"				=> $end_time,
			"inform_content"		=> $inform_content,
			"inform_type"			=> $inform_type,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_update("tbl_inform", $info, "inform_id='{$inform_id}'");
			if ($this->post->inform_file_re=='1'){
				// 附件上传
				$file = $this->model->file->upload("inform_file", $inform_id, array("txt","ppt", "xls", "xlsx", "docs", "doc", "pdf", "jpg", "png", "gif", "zip", "rar"));

				if (!empty($file)){
					$info = array(
					"inform_file" => $file['fname'],
					);

					$this->db->do_update("tbl_inform", $info, "inform_id='{$inform_id}'");
				}
			}
			// 跳转
			Helper_Client::location("修改成功", "index.php?a=inform.superiorList&inform_type={$inform_type}");
		}

		$this->tpl->assign("up_lists", $up_lists);
		$this->tpl->assign("inform_data", $inform_data);
		$this->tpl->display('inform/superior.update.tpl.php');
	}
	/** 上级通知删除 **/
	public function actionSuperiorDel()
	{


		// 类型
		$inform_type	  = (int)$this->get->inform_type;
		$inform_id	      = (int)$this->get->inform_id;
		$inform_data 	  = $this->model->inform->getinfo($inform_id);
		// 上级发布部门
		//$notice_data = $this->db->fetchRow("select * from `tbl_notice` WHERE `user_id` = {$notice_id}");
		$uid = $this->user['user_id'];

		if($inform_data['user_id']  && ($uid !=$inform_data['user_id']) ){
			Helper_Client::alert("对不起无此权限");
			//exit;
		}
		$this->db->query("DELETE  FROM `tbl_inform` WHERE inform_id='{$inform_id}'");
		$this->db->query("DELETE  FROM `tbl_inform_read` WHERE inform_id='{$inform_id}'");
		// 跳转
		Helper_Client::location("删除成功", "index.php?a=inform.superiorList&inform_type={$inform_type}");

	}
	/** 上级通知详情 **/
	public function actionSuperiorDetails()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);

		// 获取通知样式
		$style_data       = $this->model->inform->getstylemo();
		// 字体
		$style_data['style_typeface']=$this->style_name[$style_data['style_typeface']];
		// 加粗
		$style_data['style_overstriking']=$this->style_overstrikings[$style_data['style_overstriking']];
		// 斜体
		$style_data['style_italic']=$this->style_italics[$style_data['style_italic']];

		$inform_type		= $this->get->inform_type;
		$inform_id		    = $this->get->inform_id;
		// 获取信息
		$inform_lists       = $this->model->inform->getinfo($inform_id);
		$inform_lists['inform_content'] = base64_decode($inform_lists['inform_content']);
		// 上级部门名称
		$up_data = $this->model->department->getUpInfo($inform_lists['up_id']);
		$inform_lists['up_name'] = $up_data['up_name'];

		$this->tpl->assign("inform_lists", $inform_lists);
		$this->tpl->assign("style_data", $style_data);

		$this->tpl->display('inform/superior.details.tpl.php');
	}
	/** --------------------------------------- 分发列表 ----------------------------- **/
	/** 分发列表 **/
	public function actionDispenseList()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);

		$inform_type		= $this->get->inform_type;
		// 查询条件
		$up_id				= $this->get->up_id;
		$inform_title		= $this->get->inform_title;
		$from				= $this->get->from;
		$to					= $this->get->to;

		$where = "  ";
		//搜索条件
		if(!empty($up_id)){

			$where .= " AND up_id ='{$up_id}'";
			$this->tpl->assign("up_id", $up_id);
		}
		if(!empty($inform_title)){

			$where .= " AND inform_title LIKE '%{$inform_title}%'";
			$this->tpl->assign("inform_title", $inform_title);
		}
		if(!empty($from)){

			$where .= " AND end_time >= '{$from}'";
			$this->tpl->assign("from", $from);
		}
		if(!empty($to)){

			$where .= " AND end_time <= '{$to}+1'";
			$this->tpl->assign("to", $to);
		}

		// 上级部门
		$up_lists = $this->model->department->getUpAll();
		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_inform` AS a,`tbl_inform_read` AS b WHERE a.inform_id = b.inform_id AND a.inform_type = '{$inform_type}' {$where}");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);
		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}
		// 已经分发
		$inform_distribute = 1;
		$inform_lists = $this->db->fetchAll("SELECT * FROM `tbl_inform`  WHERE  inform_type = '{$inform_type}' AND inform_distribute = '{$inform_distribute}' {$where} ORDER BY inform_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
		foreach($inform_lists as $key=>$value){
			// 上级部门
			$department_lists = $this->model->department->getupinfo($value['up_id']);
			$inform_lists[$key]['up_name'] 	=$department_lists['up_name'];
			// 内容解密
			$row = base64_decode($inform_lists[$key]['inform_content']);
			// 控制内容字数
			if(strlen($row)>=21){
				$inform_lists[$key]['inform_content']=mb_substr($row,0,7,'utf8').'...';
			}
			// 控制标题字数
			if(strlen($inform_lists[$key]['inform_title'])>=60){
				$inform_lists[$key]['inform_title']=mb_substr($value['inform_title'],0,20,'utf8').'...';
			}
			// 阅读人
			$department_name = $this->model->inform->getReadAll($value['inform_id']);
			foreach ($department_name as $k => $v){
				// 获取阅读人名字
				$row = $this->model->user->getInfo($v['read_to']);
				$c = $this->model->user->getNameById($row['user_id']);
				if (!empty($c)) {
					$b[$k] = $c;
					$a = implode(',',$b);
					if (strlen($a)>10) {
						$inform_lists[$key]['name'] = mb_substr($a,0,10,utf8).'...';
					}else{
						$inform_lists[$key]['name'] = $a;
					}
				}
			}
		}

		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";
		$this->tpl->assign("page", $page->show(4, "yahoo"));

		$this->tpl->assign("inform_lists", $inform_lists);
		$this->tpl->assign("up_lists", $up_lists);
		$this->tpl->assign("inform_type", $inform_type);

		$this->tpl->display('inform/dispense.list.tpl.php');
	}
	/** 分发详情 **/
	public function actionDispenseDetails()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);

		// 获取通知样式
		$style_data       = $this->model->inform->getstylemo();
		// 字体
		$style_data['style_typeface']=$this->style_name[$style_data['style_typeface']];
		// 加粗
		$style_data['style_overstriking']=$this->style_overstrikings[$style_data['style_overstriking']];
		// 斜体
		$style_data['style_italic']=$this->style_italics[$style_data['style_italic']];

		$inform_type		= $this->get->inform_type;
		$inform_id		    = $this->get->inform_id;

		// 已经阅读
		$info = array(
		"is_read"			=> 1,
		);
		$this->db->do_update("tbl_inform_read", $info, "inform_id='{$inform_id}' AND read_to='{$this->user['user_id']}'");
		// 获取信息
		$inform_lists       = $this->model->inform->getinfo($inform_id);
		$inform_lists['inform_content'] = base64_decode($inform_lists['inform_content']);
		// 上级部门名称
		$up_data = $this->model->department->getUpInfo($inform_lists['up_id']);
		$inform_lists['up_name'] = $up_data['up_name'];
		// 阅读人员记录，学生，老师
		$department_name = $this->model->inform->getReadAll($inform_id);

		foreach ($department_name as $key => $value){

			$row = $this->model->user->getInfo($value['read_to']);

			if($row['user_type']=='staff'){
				$c = $this->model->user->getNameById($row['user_id']);
				if (!empty($c)) {
					$staff_name[$key]['staff_name'] = $c;
					$staff_name[$key]['is_read'] = $value['is_read'];
				}

			}
			if($row['user_type']=='student'){

				$c = $this->model->user->getNameById($row['user_id']);

				if (!empty($c)) {
					$student_name[$key]['student_name'] = $c;
					$student_name[$key]['is_read'] = $value['is_read'];
				}
			}

			// 判断是否阅读
			$row = $this->model->inform->getReadInfo($value['staff_id']);
			$department_name[$key]['is_read'] = $row['is_read'];
		}

		$this->tpl->assign("staff_name", $staff_name);
		$this->tpl->assign("student_name", $student_name);
		$this->tpl->assign("inform_lists", $inform_lists);
		$this->tpl->assign("style_data", $style_data);

		$this->tpl->display('inform/dispense.details.tpl.php');
	}

	/** --------------------------------------- 通知审批 ----------------------------- **/
	/** 通知审批 **/
	public function actionInformIssueList ()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);

		$inform_type    = (int)$this->get->inform_type;
		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_inform` WHERE `staff_to` is null AND inform_type = '{$inform_type}' ");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);
		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}
		// 展现没有教师接受者的全部信息
		$inform_lists = $this->db->fetchAll("SELECT * FROM `tbl_inform` WHERE `staff_to` is null AND inform_type = '{$inform_type}' ORDER BY inform_id DESC LIMIT {$start}, ".PAGE_LIMIT."");

		foreach($inform_lists as $key => $value){
			// 内容解密
			$inform_lists[$key]['inform_content'] = base64_decode($inform_lists[$key]['inform_content']);
			// 审核
			$inform_lists[$key]['is_show'] = $this->inform_judge[$value['is_show']];
			// 部门
			$department_date = $this->db->fetchRow("SELECT * FROM `tbl_department` WHERE department_id='{$value['department_id']}'");
			$inform_lists[$key]['department_name']=$department_date['department_name'];

		}

		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";
		$this->tpl->assign("page", $page->show(4, "yahoo"));

		$this->tpl->assign("inform_lists", $inform_lists);
		$this->tpl->display('inform/list.tpl.php');

	}
	/** 通知审核 **/
	public function actionInformIssueUpdate()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);

		$inform_id		= (int)$this->get->inform_id;
		$inform_type	= (int)$this->get->inform_type;
		// 通知名称
		$inform_name	= $this->inform_name[$inform_type];
		// 通知
		$inform_data	= $this->db->fetchRow("SELECT * FROM `tbl_inform` WHERE inform_id='{$inform_id}' ");

		$inform_data['inform_content']=base64_decode($inform_data['inform_content']);
		// 发布部门
		$department_data = $this->db->fetchRow("SELECT `department_name` FROM `tbl_department` WHERE department_id='{$inform_data['department_id']}' ");
		// 发布部门
		$department_lists = $this->db->fetchAll("SELECT * FROM `tbl_department`");
		$inform_data['inform_jurisdiction'] = unserialize($inform_data['inform_jurisdiction']);

		// 通知样式
		$style_data = $this->db->fetchRow("SELECT * FROM `tbl_inform_style` WHERE style_id='{$inform_data['style_id']}' ");

		//$notice_data = $this->db->fetchRow("select * from `tbl_notice` WHERE `user_id` = {$notice_id}");
		$uid = $this->user['user_id'];

		if($inform_data['user_id']  && ($uid !=$inform_data['user_id']) ){
			Helper_Client::alert("对不起无此权限");
			//exit;
		}
		if ($_POST){

			$is_show	     	    = $this->post->is_show;
			$inform_opinion     	= $this->post->inform_opinion;
			$grade_id				= (int)$this->post->grade_id;
			$class_id				= (int)$this->post->class_id;

			// 写入数据库
			$info = array(

			"is_show"				=> $is_show,
			"inform_opinion"      	=> $inform_opinion,
			"status"                => 1,

			);

			$this->db->do_update("tbl_inform", $info, "inform_id='{$inform_id}'");

			// 跳转
			Helper_Client::location("审核成功", "index.php?a=inform.informissuelist&inform_type='{$inform_type}'");
		}

		$this->tpl->assign("style_data", $style_data);
		$this->tpl->assign("inform_data", $inform_data);
		$this->tpl->assign("department_data", $department_data);
		$this->tpl->assign("department_lists", $department_lists);

		$this->tpl->assign("inform_name", $inform_name);
		if($inform_type ==3 ){
			$this->tpl->display('inform/update.tpl.php');
		}else{
			$this->tpl->display('inform/distinguish.details.tpl.php');
		}

	}
	/** 通知详情 **/
	public function actionInformDetails()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);

		// 获取通知样式
		$style_data       = $this->model->inform->getstylemo();
		// 字体
		$style_data['style_typeface']=$this->style_name[$style_data['style_typeface']];
		// 加粗
		$style_data['style_overstriking']=$this->style_overstrikings[$style_data['style_overstriking']];
		// 斜体
		$style_data['style_italic']=$this->style_italics[$style_data['style_italic']];

		$inform_id   = (int)$this->get->inform_id;
		// 通知
		$inform_data = $this->db->fetchRow("SELECT * FROM `tbl_inform` WHERE inform_id='{$inform_id}' ");
		$inform_data['inform_content'] = base64_decode($inform_data['inform_content']);
		// 发布部门
		$department_data = $this->db->fetchRow("SELECT `department_name` FROM `tbl_department` WHERE department_id='{$inform_data['department_id']}' ");
		// 查看人员或部门
		$department_lists = $this->db->fetchAll("SELECT * FROM `tbl_department`");
		$inform_data['inform_jurisdiction'] = unserialize($inform_data['inform_jurisdiction']);

		// 通知样式
		if(!empty($inform_data['style_id'])){
			$style_data = $this->db->fetchRow("SELECT * FROM `tbl_inform_style` WHERE style_id='{$inform_data['style_id']}' ");
		}

		$this->tpl->assign("style_data", $style_data);

		$this->tpl->assign("inform_data", $inform_data);
		$this->tpl->assign("department_data", $department_data);
		$this->tpl->assign("department_lists", $department_lists);
		$this->tpl->assign("style_data", $style_data);

		$this->tpl->display('inform/distinguish.details.tpl.php');
	}
	//** --------------------------- 事务交代----------------------------------**//
	/** 事务交代（中的上级通知）列表 **/
	public function actionUpList ()
	{
		// 系统日记
		$a = $_GET['a'];
		$log_name = $this->user['user_name'];
		$this->model->log->add($a,$log_name);

		// 类型进入入口
		$inform_type		= $this->get->inform_type;
		// 上级部门
		$up_lists = $this->model->department->getUpAll();
		// 查询条件
		$inform_title		= $this->get->inform_title;
		$up_id				= $this->get->up_id;
		$from				= $this->get->from;
		$to					= $this->get->to;
		$where = " ";
		//搜索条件
		if(!empty($up_id)){

			$where .= " AND a.up_id ='{$up_id}'";
			$this->tpl->assign("up_id", $up_id);
		}
		if(!empty($inform_title)){

			$where .= " AND a.inform_title LIKE '%{$inform_title}%'";
			$this->tpl->assign("inform_title", $inform_title);
		}
		if(!empty($from)){

			$where .= " AND a.end_time >= '{$from}'";
			$this->tpl->assign("from", $from);
		}
		if(!empty($to)){

			$where .= " AND a.end_time <= '{$to}+1'";
			$this->tpl->assign("to", $to);
		}
		// 完成
		if ($_POST) {
			$inform_id		= $this->post->inform_id;
			// 写入数据库
			$info = array(

			"is_show"				=> 1,
			"read_time"             => date("Y-m-d"),

			);
			$this->db->do_update("tbl_inform_read", $info, "inform_id='{$inform_id}' AND read_to='{$this->user['user_id']}'");
		}

		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_inform` AS a,`tbl_inform_read` AS b WHERE  a.inform_id = b.inform_id AND a.inform_type='{$inform_type}' AND read_to='{$this->user['user_id']}' {$where}");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);
		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}

		$inform_lists = $this->db->fetchAll("SELECT a.*,b.* FROM `tbl_inform` AS a,`tbl_inform_read` AS b WHERE a.inform_id = b.inform_id AND b.read_to={$this->user['user_id']} AND a.inform_type='{$inform_type}' {$where} ORDER BY a.inform_id DESC LIMIT {$start}, ".PAGE_LIMIT."");

		foreach($inform_lists as $key=>$value){
			// 上级部门
			$row = $this->model->department->getUpInfo($value['up_id']);
			$inform_lists[$key]['up_name'] = $row['up_name'];
			// 内容解密
			$inform_lists[$key]['inform_content'] = base64_decode($inform_lists[$key]['inform_content']);
			// 控制标题字数
			if(strlen($inform_lists[$key]['inform_title'])>=60){
				$inform_lists[$key]['inform_title']=mb_substr($value['inform_title'],0,20,'utf8').'...';
			}

		}

		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";

		$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("inform_lists", $inform_lists);
		$this->tpl->assign("department_lists", $department_lists);
		$this->tpl->assign("inform_name", $inform_name);

		$this->tpl->assign("inform_type", $inform_type);
		$this->tpl->assign("up_lists", $up_lists);
		$this->tpl->assign("user", $user);
		$this->tpl->display('inform/distinguish.list.tpl.php');

	}
	/** 下载**/
	public function actionoutput(){
		$fname = $this->get->inform_file;
		$fpath = UPLOAD_PATH."/inform_file/{$fname}";

		// 输出下载文件头s
		header("Content-Disposition: attachment; filename={$fname}");
		// 在线输出
		readfile($fpath);

	}


}

?>